package zcx;

import java.lang.reflect.Field;

/**
 * description:
 * author:zcx
 * lenovo
 * 时间：2022.02.09.17.14
 */
public class R5 {
    public static void main(String[] args) throws NoSuchFieldException {
        var u=User.class;

        //读取类上的注解
        if(u.isAnnotationPresent(Username.class)){
           var cc= u.getAnnotation(Username.class);
            System.out.println(cc.name());
        }
        //读取属性上的注解
        Field f=u.getDeclaredField("name");
        if(f.isAnnotationPresent(Username.class)){
            var uc=f.getAnnotation(Username.class);
            System.out.println(uc.name());
        }
        //读取方法上的注解
        User us=new User();
        us.show();
        try {
            var m=u.getDeclaredMethod("show");
            if(m.isAnnotationPresent(Username.class)){
                System.out.println(m.getAnnotation(Username.class).name());
            }
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
    }
}
